﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Transactions;
using System.Windows.Forms;

namespace CloudApiServer
{
    public partial class Frm_FsiSetting : Form
    {
        public Frm_FsiSetting()
        {
            InitializeComponent();
        }
        private void Frm_FsiSetting_Load(object sender, EventArgs e)
        {

            RefreshConfig();
        }
        private void button_SaveFsiInfo_Click(object sender, EventArgs e)
        {
            using (TransactionScope scope = new TransactionScope())
            {
                try
                {
                    LogHelper.Info("----------开始保存医保拓展参数配置----------");
                    FsiDatainfo.Ecccodecardno = this.textBox_EccCodeCardno.Text;
                    PublicMethod.WriteInI("FsiDatainfo", "Ecccodecardno",this.textBox_EccCodeCardno.Text);
                    FsiDatainfo.Defautlcardno = this.textBox_Defautlcardno.Text;
                    PublicMethod.WriteInI("FsiDatainfo", "Defautlcardno", this.textBox_Defautlcardno.Text);
                    FsiDatainfo.JiangsuDefautlcardno = this.textBox_JiangsuDefautlcardno.Text;
                    PublicMethod.WriteInI("FsiDatainfo", "JiangsuDefautlcardno", this.textBox_JiangsuDefautlcardno.Text);


                    FsiDatainfo.fund_pay_sumamt = Convert.ToDouble(textBox_fund_pay_sumamt.Text);
                    PublicMethod.WriteInI("FsiDatainfo", "fund_pay_sumamt", this.textBox_fund_pay_sumamt.Text);
                    FsiDatainfo.psn_cash_pay = Convert.ToDouble(textBox_psn_cash_pay.Text);
                    PublicMethod.WriteInI("FsiDatainfo", "psn_cash_pay", this.textBox_psn_cash_pay.Text);
                    FsiDatainfo.acct_pay = Convert.ToDouble(textBox_acct_pay.Text);
                    PublicMethod.WriteInI("FsiDatainfo", "acct_pay", this.textBox_acct_pay.Text);
                    FsiDatainfo.clcYearAcctPay = Convert.ToDouble(textBox_clcYearAcctPay.Text);
                    PublicMethod.WriteInI("FsiDatainfo", "clcYearAcctPay", this.textBox_clcYearAcctPay.Text);
                    FsiDatainfo.crtYearAcctPay = Convert.ToDouble(textBox_crtYearAcctPay.Text);
                    PublicMethod.WriteInI("FsiDatainfo", "crtYearAcctPay", this.textBox_crtYearAcctPay.Text);
                    FsiDatainfo.acct_mulaid_pay = Convert.ToDouble(textBox_acct_mulaid_pay.Text);
                    PublicMethod.WriteInI("FsiDatainfo", "acct_mulaid_pay", this.textBox_acct_mulaid_pay.Text);

                    FsiDatainfo.cvlserv_pay = Convert.ToDouble(textBox_cvlserv_pay.Text);
                    PublicMethod.WriteInI("FsiDatainfo", "cvlserv_pay", this.textBox_cvlserv_pay.Text);
                    FsiDatainfo.hifdm_pay = Convert.ToDouble(textBox_hifdm_pay.Text);
                    PublicMethod.WriteInI("FsiDatainfo", "hifdm_pay", this.textBox_hifdm_pay.Text);
                    FsiDatainfo.hifmi_pay = Convert.ToDouble(textBox_hifmi_pay.Text);
                    PublicMethod.WriteInI("FsiDatainfo", "hifmi_pay", this.textBox_hifmi_pay.Text);
                    FsiDatainfo.act_pay_dedc = Convert.ToDouble(textBox_act_pay_dedc.Text);
                    PublicMethod.WriteInI("FsiDatainfo", "act_pay_dedc", this.textBox_act_pay_dedc.Text);
                    FsiDatainfo.hifob_pay = Convert.ToDouble(textBox_hifob_pay.Text);
                    PublicMethod.WriteInI("FsiDatainfo", "hifob_pay", this.textBox_hifob_pay.Text);
                    FsiDatainfo.oth_pay = Convert.ToDouble(textBox_oth_pay.Text);
                    PublicMethod.WriteInI("FsiDatainfo", "oth_pay", this.textBox_oth_pay.Text);
                    FsiDatainfo.hifes_pay = Convert.ToDouble(textBox_hifes_pay.Text);
                    PublicMethod.WriteInI("FsiDatainfo", "hifes_pay", this.textBox_hifes_pay.Text);
                    FsiDatainfo.fulamt_ownpay_amt = Convert.ToDouble(textBox_fulamt_ownpay_amt.Text);
                    PublicMethod.WriteInI("FsiDatainfo", "fulamt_ownpay_amt", this.textBox_fulamt_ownpay_amt.Text);
                    FsiDatainfo.hosp_part_amt = Convert.ToDouble(textBox_hosp_part_amt.Text);
                    PublicMethod.WriteInI("FsiDatainfo", "hosp_part_amt", this.textBox_hosp_part_amt.Text);
                    FsiDatainfo.inscp_scp_amt = Convert.ToDouble(textBox_inscp_scp_amt.Text);
                    PublicMethod.WriteInI("FsiDatainfo", "inscp_scp_amt", this.textBox_inscp_scp_amt.Text);
                    FsiDatainfo.maf_pay = Convert.ToDouble(textBox_maf_pay.Text);
                    PublicMethod.WriteInI("FsiDatainfo", "maf_pay", this.textBox_maf_pay.Text);
                    FsiDatainfo.overlmt_selfpay = Convert.ToDouble(textBox_overlmt_selfpay.Text);
                    PublicMethod.WriteInI("FsiDatainfo", "overlmt_selfpay", this.textBox_overlmt_selfpay.Text);
                    FsiDatainfo.preselfpay_amt = Convert.ToDouble(textBox_preselfpay_amt.Text);
                    PublicMethod.WriteInI("FsiDatainfo", "preselfpay_amt", this.textBox_preselfpay_amt.Text);

                    FsiEpcTokeninfo.appId = this.textBox_appId.Text;
                    PublicMethod.WriteInI("FsiEpcTokeninfo", "appId", this.textBox_appId.Text);
                    FsiEpcTokeninfo.appSecret = this.textBox_appSecret.Text;
                    PublicMethod.WriteInI("FsiEpcTokeninfo", "appSecret", this.textBox_appSecret.Text);
                    FsiEpcTokeninfo.privateKey = this.textBox_privateKey.Text;
                    PublicMethod.WriteInI("FsiEpcTokeninfo", "privateKey", this.textBox_privateKey.Text);
                    FsiEpcTokeninfo.publicKey = this.textBox_publicKey.Text;
                    PublicMethod.WriteInI("FsiEpcTokeninfo", "publicKey", this.textBox_publicKey.Text);

                    LogHelper.Info("----------结束保存医保拓展参数配置----------");

                    scope.Complete();
                    MessageBox.Show("保存成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                }
                catch (Exception ex)
                {
                    MessageBox.Show($"保存失败！错误内容:{ex.Message}", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }

        //public void Save()
        //{
        //    using (TransactionScope scope = new TransactionScope())
        //    {
        //        try
        //        {
        //            if (FsiDatainfo.fund_pay_sumamt + FsiDatainfo.psn_cash_pay + FsiDatainfo.acct_pay != 1)
        //            {
        //                throw new Exception("基金支付比例+现金自付比例+账户支付比例不等于1！请重新设置！");
        //            }
        //            if (FsiDatainfo.clcYearAcctPay + FsiDatainfo.crtYearAcctPay != FsiDatainfo.acct_pay)
        //            {
        //                throw new Exception("当年账户比例+历年账户比例不等于账户支付比例！请重新设置！");
        //            }
        //            FsiDatainfo.Ecccodecardno = this.textBox_EccCodeCardno.Text;
        //            FsiDatainfo.fund_pay_sumamt = Convert.ToDouble(textBox_fund_pay_sumamt.Text);
        //            FsiDatainfo.psn_cash_pay = Convert.ToDouble(textBox_psn_cash_pay.Text);
        //            FsiDatainfo.acct_pay = Convert.ToDouble(textBox_acct_pay.Text);
        //            FsiDatainfo.clcYearAcctPay = Convert.ToDouble(textBox_clcYearAcctPay.Text);
        //            FsiDatainfo.crtYearAcctPay = Convert.ToDouble(textBox_crtYearAcctPay.Text);


        //            scope.Complete();
        //            MessageBox.Show("保存成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
        //        }
        //        catch (Exception ex)
        //        {

        //            MessageBox.Show($"保存失败！错误内容:{ex.Message}", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
        //        }
        //    }
        //}
        /// <summary>
        /// 刷新配置
        /// </summary>
        public void RefreshConfig()
        {
            PublicMethod.RefreshConfiguration();

            this.textBox_EccCodeCardno.Text = FsiDatainfo.Ecccodecardno;
            this.textBox_Defautlcardno.Text = FsiDatainfo.Defautlcardno.ToString();
            this.textBox_JiangsuDefautlcardno.Text=FsiDatainfo.JiangsuDefautlcardno.ToString();

            this.textBox_fund_pay_sumamt.Text = FsiDatainfo.fund_pay_sumamt.ToString();
            this.textBox_psn_cash_pay.Text = FsiDatainfo.psn_cash_pay.ToString();
            this.textBox_acct_pay.Text = FsiDatainfo.acct_pay.ToString();
            this.textBox_clcYearAcctPay.Text = FsiDatainfo.clcYearAcctPay.ToString();
            this.textBox_crtYearAcctPay.Text = FsiDatainfo.crtYearAcctPay.ToString();
            this.textBox_acct_mulaid_pay.Text = FsiDatainfo.acct_mulaid_pay.ToString();

            this.textBox_cvlserv_pay.Text = FsiDatainfo.cvlserv_pay.ToString();
            this.textBox_hifdm_pay.Text = FsiDatainfo.hifdm_pay.ToString();
            this.textBox_hifmi_pay.Text = FsiDatainfo.hifmi_pay.ToString();
            this.textBox_act_pay_dedc.Text = FsiDatainfo.act_pay_dedc.ToString();
            this.textBox_hifob_pay.Text = FsiDatainfo.hifob_pay.ToString();
            this.textBox_oth_pay.Text = FsiDatainfo.oth_pay.ToString();
            this.textBox_hifes_pay.Text = FsiDatainfo.hifes_pay.ToString();
            this.textBox_fulamt_ownpay_amt.Text = FsiDatainfo.fulamt_ownpay_amt.ToString();
            this.textBox_hosp_part_amt.Text = FsiDatainfo.hosp_part_amt.ToString();
            this.textBox_inscp_scp_amt.Text = FsiDatainfo.inscp_scp_amt.ToString();
            this.textBox_maf_pay.Text = FsiDatainfo.maf_pay.ToString();
            this.textBox_overlmt_selfpay.Text = FsiDatainfo.overlmt_selfpay.ToString();
            this.textBox_preselfpay_amt.Text = FsiDatainfo.preselfpay_amt.ToString();

            this.textBox_appId.Text = FsiEpcTokeninfo.appId.ToString();
            this.textBox_appSecret.Text = FsiEpcTokeninfo.appSecret.ToString();
            this.textBox_privateKey.Text = FsiEpcTokeninfo.privateKey.ToString();
            this.textBox_publicKey.Text = FsiEpcTokeninfo.publicKey.ToString();
        }


        private void button_RefreshFsiInfo_Click(object sender, EventArgs e)
        {
            try
            {
                RefreshConfig();
                MessageBox.Show("刷新成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
            }
            catch (Exception ex)
            {
                MessageBox.Show($"数据刷新失败！错误内容:{ex.Message}", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
    }
}
